package com.chenjiahao.kaiyanwan.ui.mine

import android.app.Activity
import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.chenjiahao.kaiyanwan.BUNDLE_VIDEO_DATA
import com.chenjiahao.kaiyanwan.R
import com.chenjiahao.kaiyanwan.base.CommonAdapter
import com.chenjiahao.kaiyanwan.base.ViewHolder
import com.chenjiahao.kaiyanwan.durationFormat
import com.chenjiahao.kaiyanwan.startActivity
import com.chenjiahao.kaiyanwan.ui.videodetail.VideoDetailActivity
import com.hazz.kotlinmvp.mvp.model.bean.HomeBean

/**
 * Created by xuhao on 2017/12/11.
 * desc:
 */
class WatchHistoryAdapter(
    context: Context,
    dataList: ArrayList<HomeBean.Issue.Item>,
    layoutId: Int
) : CommonAdapter<HomeBean.Issue.Item>(context, dataList, layoutId) {


    //绑定数据
    override fun bindData(holder: ViewHolder, data: HomeBean.Issue.Item, position: Int) {
        with(holder) {
            setText(R.id.tv_title, data.data?.title!!)
            setText(R.id.tv_tag, "#${data.data.category} / ${durationFormat(data.data.duration)}")
            setImagePath(
                R.id.iv_video_small_card,
                object : ViewHolder.HolderImageLoader(data.data.cover.detail) {
                    override fun loadImage(iv: ImageView, path: String) {
                        Glide.with(mContext)
                            .load(path)
                            .placeholder(R.drawable.placeholder_banner)
                            .transition(DrawableTransitionOptions().crossFade())
                            .into(iv)
                    }
                })
        }
        holder.getView<TextView>(R.id.tv_title)
            .setTextColor(ContextCompat.getColor(mContext, R.color.color_black))
        holder.setOnItemClickListener(listener = View.OnClickListener {
            startActivity<VideoDetailActivity>(
                mContext as Activity,
                holder.getView(R.id.iv_video_small_card)
            ) {
                putExtra(BUNDLE_VIDEO_DATA, data)
                putExtra(VideoDetailActivity.TRANSITION, true)
            }
        })
    }


}